package org.concept.chinachesspieces.core;

/**
 * @author xww 工具类
 */
public class Utils {

	/**
	 * 红黑互换
	 * 
	 * @param bs
	 *            棋盘
	 * @return 红黑互换后的棋盘
	 */
	public static byte[][] turnRedBlack(byte[][] bs) {
		byte[][] result = new byte[10][9];
		for (int i = 0; i < bs.length; i++) {
			for (int j = 0; j < bs[i].length; j++) {
				result[9 - i][8 - j] = bs[i][j];
			}
		}
		return result;
	}

	/**
	 * 做过一步棋之后的变化
	 * 
	 * @param qj
	 *            棋盘
	 * @param action
	 *            走的一步棋，例如：2345即坐标[2,3]的棋子移动到坐标[4,5]
	 */
	public static void nextchess(byte[][] qj, int action) {
		int from = action / 100;
		int to = action - from * 100;
		int fromx = from / 10;
		int fromy = from - fromx * 10;
		int tox = to / 10;
		int toy = to - tox * 10;
		qj[tox][toy] = qj[fromx][fromy];
		qj[fromx][fromy] = Constants.EMPTY;
	}

	/**
	 * 走过N步棋之后的变化
	 * 
	 * @param qj
	 *            棋盘
	 * @param action
	 *            走的N步棋
	 */
	public static void nextNchess(byte[][] qj, int[] actions) {
		for (int i = 0; i < actions.length; i++) {
			int action = actions[i];
			int from = action / 100;
			int to = action - from * 100;
			int fromx = from / 10;
			int fromy = from - fromx * 10;
			int tox = to / 10;
			int toy = to - tox * 10;
			qj[tox][toy] = qj[fromx][fromy];
			qj[fromx][fromy] = Constants.EMPTY;
		}
	}

}
